;
var _pageUrl = "/htmlWeb/certiAudit/list";
var pageGrid;
function editDataN(id) {
    $.ajax({
        url: "htmlWeb/certiAudit/certiAuditData",
        type: 'GET',
        dataType: "json",
        data: {
            id: id, status: 2
        },
        success: function (result) {
            if(result.msg == 'success'){
                $(".mainDiv").load('htmlWeb/systemCertiAuditHtml', '', function () {
                    $.getScript("../../by-webhtml/assets/js/system/system_certiAudit.js");
                });
            }else {
                alert("认证不通过失败");
            }
        },
        error: function () {

        }
    });
}
function editDataY(id) {
    $.ajax({
        url: "htmlWeb/certiAudit/certiAuditData",
        type: 'GET',
        dataType: "json",
        data: {
            id: id, status: 1
        },
        success: function (result) {
            if(result.msg == 'success'){
                $(".mainDiv").load('htmlWeb/systemCertiAuditHtml', '', function () {
                    $.getScript("../../by-webhtml/assets/js/system/system_certiAudit.js");
                });
            }else {
                alert("认证通过失败");
            }
        },
        error: function () {

        }
    });
}
/**
 * 时间字符串转时间戳
 * datestr: 2017-07-30 19:15:12
 */
var date2timestamp = function (datestr) {
    if(datestr == null) return;
    var timestamp2 = Date.parse(new Date(datestr));
    timestamp2 = timestamp2 / 1000;
    return timestamp2;
}
function init() {
    _init_area();
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
        // min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16', //最大日期
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
        max: '2099-06-16',
        event: 'click',
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    $.post("htmlWeb/certiAudit/getSearchOption", function (data) {
        var _authType = "";
        var _certificatesType = "";
        var _status = "";
        $.each(data.authType, function (index, obj) {
            var opt = obj.split(";");
            _authType += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#authType").append('<option value=""></option>'+_authType);
        $.each(data.certificatesType, function (index, obj) {
            var opt = obj.split(";");
            _certificatesType += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $("#certificatesType").append(_certificatesType);
        if(data.authStatus != undefined){
            $.each(data.authStatus, function (index, obj) {
                var opt = obj.split(";");
                _status += '<option value="' + opt[0] + '">' + opt[1] + '</option>';
            });
            $("#status").append(_status);
        }
    });
   /* $("#applyCerti").click(function () {
        var userId = 92;
        var businessType = 3;
        var dailishangId = 22;
        $(".mainDiv").load('htmlWeb/systemApplyCertiHtml', '', function () {
            $("#userId").val(userId);
            $("#businessType").val(businessType);
            $("#dailishangId").val(dailishangId);
            $.getScript("../../by-webhtml/assets/js/system/system_applyCerti.js");
        });
    });*/
    $(".conBut").click(function () {
        var o = $("#authSearchForm").serializeSearchForm();
        if(o.start != undefined && o.start != null){
            o.start = date2timestamp(o.start+" 00:00:00");
        }if(o.end != undefined && o.end != null){
            o.end = date2timestamp(o.end+" 23:59:59");
        }
        pageGrid.search(o);
    });
    $("#imgCancel").click(function () {
        $(".roleNew,.layerDele").css({
           display: "none"
        });
    });
}
function getParams() {
    var s = $("#authSearchForm").serializeSearchForm();
    return s;
}
function pageBar() {
    pageGrid=  $("#pager").createPage({
        url: _pageUrl,
        params: {status: $("#status").val()},
        ajaxBackFn: function (data) {
            var _gridHtml = '';
            var _status = $("#status").val();
            $.each(data.rows, function (index, row) {
                _gridHtml += '<tr>' +
                    '<td><p>' + row.id + '</p></td>' +
                    '<td><p>' + (row.userCnName == null?'':row.userCnName)   + '</p></td>' +
                    '<td><p>' + (row.userMobile == null ?"":row.userMobile) + '</p></td>' +
                    '<td><p>' + (row.imgUrl == null ? "":'<a href="javascript:void(0);" onclick="viewImg(this)"><img src="'+_imgesByUrl + row.imgUrl + '" width="60px" height="40px"/></a>') + '</p></td>' +
                    '<td><p>' + row.authTypeName + '</p></td>' +
                    '<td><p>' + row.authLevel + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '<td><p>' +( row.province == null?"": row.province) + '</p></td>' +
                    '<td><p>' + (row.city==null?"":row.city) + '</p></td>' +
                    '<td><p>' + (row.district==null ? '':row.district) + '</p></td>' +
                    '<td><p>' + (row.dailishang == null ? '':row.dailishang) + '</p></td>' +
                    '<td><p>' + row.createTimeName + '</p></td>' +
                    '<td><span class="userSpan"><p>' ;
                   if(_status == -1){
                       _gridHtml += '<a href="javascript:editDataY(' + row.id + ')">认证通过</a>' +
                       '<a href="javascript:editDataN(' + row.id + ')">认证不通过</a>' ;
                   }
                    '</p></span></td></tr>';
            });
            $("#certiAuditGrid tr:not(:first)").html("");
            $('#certiAuditGrid').append(_gridHtml);
        }
    });
}
function viewImg(img) {
    $("#file_img img").attr("src",$(img).find('img').attr("src"));
    $("#file_img").css("width",'656px');
    $("#file_img").css("height",'400px');
    $(".layerDele").css("width",'656px');
    $(".layerDele").css("height",'580px');
    $(".roleNew,.layerDele").css({
        top:($(window).height()-$(".roleNew,.imges").height())/2+$(window).scrollTop()+"px",
        display:"block"
    });
}
$(function () {
    init();
    setTimeout(function () {
        pageBar();
    },500);
});